<?php

namespace App\Models\Common;

use Illuminate\Database\Eloquent\Model;

class CollTown extends Model{
    protected $table = 'coll_town';
    protected $primaryKey = 'id';
    public $timestamps = false;
    protected $guarded = [];

    /**
     * 获取乡镇信息
     * @return array
     * $pid:省份的id
     */
    public static function getTown($pid){

        $town = self::where('pid', $pid)->get();
        $town = setSort($town);
        $townArray = array();
        foreach($town as $key => $value){
            $townArray[] = array('value' => $value['cid'], 'text' => $value['name']);
        }
        return $townArray;
    }

    /**
     * 获取乡镇的中文
     * $cid:选项编号
     * @return： 选项名称
     */
    public static function getTownName($cid){
        $town = self::where('cid', $cid)->first();
        if(isset($town)){
            return $town->name;
        }
        return '';
    }
}
